/**
 * 2017年12月19日
 */
package exp.paper.core;

import exp.algorithm.sic.GaussianArray;
import exp.algorithm.sic.TimeSeries;

/**
 * @author Alex
 *
 */
public class LightOctaveSpace {
	LightOctaveSpace down; // down指的是下一个8度空间
	LightOctaveSpace up;
	TimeSeries baseImg; // 当前8度空间的原始图片，由上一个8度空间的某层（默认为倒数第三层）获取
	public float baseScale; // 原始图片在塔中的原始尺度
	public int indexInPyramid;
	public TimeSeries[] smoothedImgs; // 同一尺寸用不同模糊因子模糊后的高斯图像集
	public TimeSeries[] diffImags; // 由smoothedImgs得到的差分图集

		
	public LightOctaveSpace( ) {
		
	}
	
	public String toString(){
		String [] r = new String[this.smoothedImgs.length];
		for(int i= 0;i<r.length;i++){
			r[i] = smoothedImgs[i].toString();
		}
		return "\n"+String.join("\n", r)+"\n";
		
	}
	
	public TimeSeries getLastGaussianImg() {
		if (this.smoothedImgs.length < 2) {
			throw new java.lang.IllegalArgumentException(
					"err: too few gaussian maps.");
		}
		return (this.smoothedImgs[this.smoothedImgs.length - 2]);
	}

	public void makeGaussianImgs(TimeSeries base, float baseScale,int scales, float sigma) {
		smoothedImgs = new TimeSeries[scales + 3];
		this.baseScale = baseScale;
		TimeSeries prev = base;
		smoothedImgs[0] = base;

		float w = sigma;
		float kTerm = (float) Math.sqrt(Math.pow(Math.pow(2.0, 1.0 / scales),2.0) - 1.0);
		for (int i = 1; i < smoothedImgs.length; i++) {
			GaussianArray gauss = new GaussianArray(w * kTerm);
			prev = smoothedImgs[i] = gauss.convolve(prev);
			w *= Math.pow(2.0, 1.0 / scales);
		}
	}

	public void makeGaussianDiffImgs() {
		diffImags = new TimeSeries[smoothedImgs.length - 1];
		for (int sn = 0; sn < diffImags.length; sn++) {
			diffImags[sn] = TimeSeries.minus(smoothedImgs[sn + 1],smoothedImgs[sn]);
		}
	}


	public void clear() {
	}

	/**
	 * 用于传递引用的数据结构
	 */
	static class RefCheckMark {

		boolean isMin;
		boolean isMax;
	}

	/**
	 * 用于传递引用的数据结构
	 */
	static class RefPeakValueAndDegreeCorrection {

		float peakValue;
		float degreeCorrection;
	}
}
